package com.ruoyi.common.core.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;

public class CodeMaxIdUtil {


    public static synchronized Long genLongUniqueKey() {
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        String id = String.valueOf(snowflake.nextId());
        return Long.valueOf(id.substring(id.length() - 11));

    }

    public static synchronized String genUniqueKey(String prefix) {
        long snowflakeNextId1 = IdUtil.getSnowflakeNextId();
        String id = String.valueOf(snowflakeNextId1);
        return prefix + id.substring(id.length() - 15);
    }

    public static synchronized String genIntUniqueKey(String prefix) {
        Snowflake snowflake = IdUtil.getSnowflake(1, 1);
        String id = String.valueOf(snowflake.nextId());
        System.out.println(id);
        return prefix + id.substring(id.length() - 9);

    }

    public static void main(String[] args) {
        System.out.println(CodeMaxIdUtil.genUniqueKey("TRADE"));
//        System.out.println(CodeMaxIdUtil.genIntUniqueKey("OR"));
    }
}
